package com.akoj.anmu.config;
import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Redssion配置类
 */
@Configuration
@ConfigurationProperties(prefix = "spring.redis")
@Data
public class RedissionConfig {

    private String host;
    private int port;
    private int database;

    @Bean
    public RedissonClient redissonClient(){
        //创建配置
        Config config = new Config();
        //创建连接
        String redissionAddress = String.format("redis://%s:%s", host, port);
        config.useSingleServer().setAddress(redissionAddress).setDatabase(database);
        //返回客户端实例
        RedissonClient redisson = Redisson.create(config);

        return redisson;
    }

}
